package com.wrench.elevator.jedis;

import redis.clients.jedis.Jedis;

import com.elevatorbus.banshou.mina.FileUploadRequest;
import com.wrench.elevator.util.SerializeUtil;

public class JedisFileUploadRequestUtil
{
    public static void set(String sessionId, FileUploadRequest request)
    {
        byte[] value = SerializeUtil.serialize(request);
        byte[] key = sessionId.getBytes();
        Jedis jedis = RedisUtil.getJedis();
        jedis.set(key, value);
        jedis.expire(key, 30);
        RedisUtil.returnResource(jedis);
    }
    
    public static Object get(String sessionId)
    {
        byte[] value = null;
        byte[] key = sessionId.getBytes();
        Jedis jedis = RedisUtil.getJedis();
        value = jedis.get(key);
        Object obj = null;
        obj = SerializeUtil.unserialize(value);
        RedisUtil.returnResource(jedis);
        return obj;
        
    }
    
    public static void del(String sessionId)
    {
        byte[] key = sessionId.getBytes();
        Jedis jedis = RedisUtil.getJedis();
        jedis.del(key);
        RedisUtil.returnResource(jedis);
        
    }
}
